﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace robotGUI
{
    public partial class CPUgraph : UserControl
    {
        List<int> data;
        public CPUgraph()
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw, true);
            data = new List<int>();
            InitializeComponent();
        }

        private void CPUgraph_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            LinearGradientBrush lg = new LinearGradientBrush(new Rectangle(0, 0, 1, ClientSize.Height), Color.Tomato, Color.LightGreen, (float)90);
            Pen p = new Pen(lg);
            Brush b = new SolidBrush(Color.White);
            g.FillRectangle(b, 0, 0, ClientSize.Width, ClientSize.Height);
            for (int x = 0; x <= ClientSize.Width; x++)
            {
                if (x < data.Count)
                {
                    int y = (int)((data[x] / 100f) * this.ClientSize.Height);
                    g.DrawLine(p, ClientSize.Width - x, ClientSize.Height, ClientSize.Width - x, ClientSize.Height - y);
                }
            }
            p.Dispose();
            b.Dispose();
        }
        public void Add(int percent)
        {
            if (percent < 0) percent = 0;
            if (percent > 100) percent = 100;
            data.Insert(0, percent);
            if (data.Count > ClientSize.Width+1)
                data.RemoveAt(data.Count - 1);
            Invalidate();
        }
            

    }
}
